//引入Vue
import Vue from 'vue'
//引入App组件，他是所有组件的父组件
import App from './App.vue'
import router from './router/index';
//按需导入element-ui
import {Form,FormItem,Input,Button,Message,Tag,Container,Header,Aside,
        Main,Menu,Submenu,MenuItem,Badge,Link,Breadcrumb,BreadcrumbItem,Card,Row,Col,
        Table,TableColumn,Switch,Tooltip,Pagination,Dialog,MessageBox,Tree,Select,Option,Cascader,Alert,
        TabPane,Tabs,Step,Steps,CheckboxGroup,Checkbox,Upload,Timeline,TimelineItem} 
from 'element-ui';
//导入自定义全局样式
import './assets/css/global.css'
//导入字体图标(阿里图标库)
import './assets/fonts/iconfont.css'
//导入axios
import axios from 'axios'
//导入vue-table-with-tree-grid
import TreeTable from 'vue-table-with-tree-grid'
//导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
//导入富文本编辑器对应的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import _ from 'lodash'
//导入nprogress包和对应的css和js
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
//配置请求的根路径(调用后台接口)
axios.defaults.baseURL='http://127.0.0.1:8888/api/private/v1/'
//axios请求拦截添加token，保证拥有获取数据的权限
//在request拦截器中，展示进度条
axios.interceptors.request.use(config=>{
  NProgress.start()
  //为请求头对象，添加token验证的Authorization字段
  config.headers.Authorization=window.sessionStorage.getItem('token')
  //在最后必须return config
  return config
})
//在response拦截器中，隐藏进度条
axios.interceptors.response.use(config=>{
  NProgress.done()
  return config
})
//每一个组件都可以找到发起Ajax请求
Vue.prototype.$http=axios
//不产生生产提示警告
Vue.config.productionTip=false

//注册为全局可用的组件
Vue.component('tree-table',TreeTable)
//将富文本编辑器注册为全局可用组件
Vue.use(VueQuillEditor)

Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Button)
Vue.use(Tag)
Vue.use(Container)
Vue.use(Header)
Vue.use(Aside)
Vue.use(Main)
Vue.use(Menu)
Vue.use(Submenu)
Vue.use(MenuItem)
Vue.use(Badge)
Vue.use(Link)
Vue.use(Breadcrumb)
Vue.use(BreadcrumbItem)
Vue.use(Card)
Vue.use(Col)
Vue.use(Row)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Switch)
Vue.use(Tooltip)
Vue.use(Pagination)
Vue.use(Dialog)
Vue.use(Tree)
Vue.use(Select)
Vue.use(Option)
Vue.use(Cascader)
Vue.use(Alert)
Vue.use(TabPane)
Vue.use(Tabs)
Vue.use(Step)
Vue.use(Steps)
Vue.use(Checkbox)
Vue.use(CheckboxGroup)
Vue.use(Upload)
Vue.use(Timeline)
Vue.use(TimelineItem)
//把弹框组件挂载到原型对象上
Vue.prototype.$message=Message 
Vue.prototype.$confirm=MessageBox.confirm
//注册全局格式化时间过滤器
Vue.filter('dateFormat',function(originVal){
   const dt = new Date(originVal*1000)
   const y =dt.getFullYear()
   const m=(dt.getMonth()+1+'').padStart(2,'0')
   const d=(dt.getDate()+'').padStart(2,'0')
   const hh=(dt.getHours()+'').padStart(2,'0')
   const mm=(dt.getMinutes()+'').padStart(2,'0')
   const ss=(dt.getSeconds()+'').padStart(2,'0')
   return `${y}-${m}-${d} ${hh}:${mm}:${ss}`

})
new Vue({
  el:'#app',
  router:router,
  render: h => h(App),
})
